﻿using System;
using System.Globalization;
using Microsoft.Xna.Framework;

namespace XTengine.ComponentModel
{
    public class Vector4Converter : TypeConverter<Vector4>
    {
        public override Vector4 ConvertFrom(string value)
        {
            string[] splits = value.Split(',');

            if (splits.Length < 4)
                return Vector4.Zero;

            CultureInfo eng = new CultureInfo("en-US");

            Vector4 result = new Vector4();
            result.X = Single.Parse(splits[0], eng);
            result.Y = Single.Parse(splits[1], eng);
            result.Z = Single.Parse(splits[2], eng);
            result.W = Single.Parse(splits[3], eng);

            return result;
        }

        public override string ConvertTo(Vector4 value)
        {
            return value.X + "," + value.Y + "," + value.Z + "," + value.W;
        }
    }
}